/*
 * Copyright (c) 2019 SUSE LLC
 *
 * Licensed under LGPL-2.1 (see LICENSE)
 */

#include "common.h"
#include "scsi_trace.h"

#define CASE_STR(x) case x: return #x;

_Use_decl_annotations_
PCHAR
WnbdToStringSrbFunction(ULONG SrbFunction)
{
    switch(SrbFunction) {
    CASE_STR(SRB_FUNCTION_EXECUTE_SCSI)
    CASE_STR(SRB_FUNCTION_CLAIM_DEVICE)
    CASE_STR(SRB_FUNCTION_IO_CONTROL)
    CASE_STR(SRB_FUNCTION_RECEIVE_EVENT)
    CASE_STR(SRB_FUNCTION_RELEASE_QUEUE)
    CASE_STR(SRB_FUNCTION_ATTACH_DEVICE)
    CASE_STR(SRB_FUNCTION_RELEASE_DEVICE)
    CASE_STR(SRB_FUNCTION_SHUTDOWN)
    CASE_STR(SRB_FUNCTION_FLUSH)
    CASE_STR(SRB_FUNCTION_PROTOCOL_COMMAND)
    CASE_STR(SRB_FUNCTION_ABORT_COMMAND)
    CASE_STR(SRB_FUNCTION_RELEASE_RECOVERY)
    CASE_STR(SRB_FUNCTION_RESET_BUS)
    CASE_STR(SRB_FUNCTION_RESET_DEVICE)
    CASE_STR(SRB_FUNCTION_TERMINATE_IO)
    CASE_STR(SRB_FUNCTION_FLUSH_QUEUE)
    CASE_STR(SRB_FUNCTION_REMOVE_DEVICE)
    CASE_STR(SRB_FUNCTION_WMI)
    CASE_STR(SRB_FUNCTION_LOCK_QUEUE)
    CASE_STR(SRB_FUNCTION_UNLOCK_QUEUE)
    CASE_STR(SRB_FUNCTION_QUIESCE_DEVICE)
    CASE_STR(SRB_FUNCTION_RESET_LOGICAL_UNIT)
    CASE_STR(SRB_FUNCTION_SET_LINK_TIMEOUT)
    CASE_STR(SRB_FUNCTION_LINK_TIMEOUT_OCCURRED)
    CASE_STR(SRB_FUNCTION_LINK_TIMEOUT_COMPLETE)
    CASE_STR(SRB_FUNCTION_POWER)
    CASE_STR(SRB_FUNCTION_PNP)
    CASE_STR(SRB_FUNCTION_DUMP_POINTERS)
    CASE_STR(SRB_FUNCTION_FREE_DUMP_POINTERS)
    default:
        return "UNKNOWN_SRB_FUNCTION";
    }
}

_Use_decl_annotations_
PCHAR
WnbdToStringSrbStatus(UCHAR SrbStatus)
{
    switch(SrbStatus) {
    CASE_STR(SRB_STATUS_PENDING)
    CASE_STR(SRB_STATUS_SUCCESS)
    CASE_STR(SRB_STATUS_ABORTED)
    CASE_STR(SRB_STATUS_ABORT_FAILED)
    CASE_STR(SRB_STATUS_ERROR)
    CASE_STR(SRB_STATUS_BUSY)
    CASE_STR(SRB_STATUS_INVALID_REQUEST)
    CASE_STR(SRB_STATUS_INVALID_PATH_ID)
    CASE_STR(SRB_STATUS_NO_DEVICE)
    CASE_STR(SRB_STATUS_TIMEOUT)
    CASE_STR(SRB_STATUS_SELECTION_TIMEOUT)
    CASE_STR(SRB_STATUS_COMMAND_TIMEOUT)
    CASE_STR(SRB_STATUS_MESSAGE_REJECTED)
    CASE_STR(SRB_STATUS_BUS_RESET)
    CASE_STR(SRB_STATUS_PARITY_ERROR)
    CASE_STR(SRB_STATUS_REQUEST_SENSE_FAILED)
    CASE_STR(SRB_STATUS_NO_HBA)
    CASE_STR(SRB_STATUS_DATA_OVERRUN)
    CASE_STR(SRB_STATUS_UNEXPECTED_BUS_FREE)
    CASE_STR(SRB_STATUS_PHASE_SEQUENCE_FAILURE)
    CASE_STR(SRB_STATUS_BAD_SRB_BLOCK_LENGTH)
    CASE_STR(SRB_STATUS_REQUEST_FLUSHED)
    CASE_STR(SRB_STATUS_INVALID_LUN)
    CASE_STR(SRB_STATUS_INVALID_TARGET_ID)
    CASE_STR(SRB_STATUS_BAD_FUNCTION)
    CASE_STR(SRB_STATUS_ERROR_RECOVERY)
    CASE_STR(SRB_STATUS_NOT_POWERED)
    CASE_STR(SRB_STATUS_LINK_DOWN)
// Recent SDK additions
#ifdef SRB_STATUS_INSUFFICIENT_RESOURCES
    CASE_STR(SRB_STATUS_INSUFFICIENT_RESOURCES)
#endif
#ifdef SRB_STATUS_THROTTLED_REQUEST
    CASE_STR(SRB_STATUS_THROTTLED_REQUEST)
#endif
    default:
        return "UNKNOWN_SRB_STATUS";
    }
}

_Use_decl_annotations_
PCHAR
WnbdToStringPnpMinorFunction(UCHAR PnpMinorFunction)
{
    switch (PnpMinorFunction) {
    CASE_STR(IRP_MN_START_DEVICE)
    CASE_STR(IRP_MN_QUERY_REMOVE_DEVICE)
    CASE_STR(IRP_MN_REMOVE_DEVICE)
    CASE_STR(IRP_MN_CANCEL_REMOVE_DEVICE)
    CASE_STR(IRP_MN_STOP_DEVICE)
    CASE_STR(IRP_MN_QUERY_STOP_DEVICE)
    CASE_STR(IRP_MN_CANCEL_STOP_DEVICE)
    CASE_STR(IRP_MN_QUERY_DEVICE_RELATIONS)
    CASE_STR(IRP_MN_QUERY_INTERFACE)
    CASE_STR(IRP_MN_QUERY_CAPABILITIES)
    CASE_STR(IRP_MN_QUERY_RESOURCES)
    CASE_STR(IRP_MN_QUERY_RESOURCE_REQUIREMENTS)
    CASE_STR(IRP_MN_QUERY_DEVICE_TEXT)
    CASE_STR(IRP_MN_FILTER_RESOURCE_REQUIREMENTS)
    CASE_STR(IRP_MN_READ_CONFIG)
    CASE_STR(IRP_MN_WRITE_CONFIG)
    CASE_STR(IRP_MN_EJECT)
    CASE_STR(IRP_MN_SET_LOCK)
    CASE_STR(IRP_MN_QUERY_ID)
    CASE_STR(IRP_MN_QUERY_PNP_DEVICE_STATE)
    CASE_STR(IRP_MN_QUERY_BUS_INFORMATION)
    CASE_STR(IRP_MN_DEVICE_USAGE_NOTIFICATION)
    CASE_STR(IRP_MN_SURPRISE_REMOVAL)
    CASE_STR(IRP_MN_DEVICE_ENUMERATED)
    default:
        return "IRP_MN_UNKNOWN";
    }
}

_Use_decl_annotations_
PCHAR
WnbdToStringScsiAdapterCtrlType(UCHAR ControlType)
{
    switch (ControlType){
    CASE_STR(ScsiQuerySupportedControlTypes)
    CASE_STR(ScsiStopAdapter)
    CASE_STR(ScsiRestartAdapter)
    CASE_STR(ScsiSetBootConfig)
    CASE_STR(ScsiSetRunningConfig)
    CASE_STR(ScsiAdapterControlMax)
    default:
        return "Unknown";
    }
}